<template>
    <div>
        <div class="tc m-t-6 p-b-10 bb-1-e">
            <img src="../img/logo.png" alt="" class="register-logo">
        </div>
        <nav>
            <ul>
                <li class="width-75 bb-1-e z-header">
                    <span class="c-b1">手机号:</span>
                    <input type="text" class="b-0" v-model="username">
                </li>
                <li class="width-75 bb-1-e z-header">
                    <span class="c-b1">密码:</span>
                    <input type="text" class="b-0" v-model="Password">
                </li>
                <li class="tc">
                    <button class="register-button c-f b-c2" @click="login">登录</button>
                </li>
                <li class="flex width-75 c-3 m-t-28">
                    <p>
                        <router-link to="/passwordForget">
                            找回密码
                        </router-link>
                    </p>
                    <p>
                        <router-link to="/register">
                            没有账号，去注册
                        </router-link>
                    </p>
                </li>
            </ul>
        </nav>
    </div>
</template>
<script>
import Vue from 'vue'
import { MessageBox, Toast } from 'mint-ui';
import { vali } from '../assets/js/common'
Vue.prototype.$vali = vali

export default {
    data() {
        return {
            username: '',
            Password: ''
        }
    },
    methods: {
        login() {
            var params = new URLSearchParams();
            params.append("username", this.username);
            params.append("Password", this.Password);
            if (this.$vali(this.username, /^1[0-9]{10}$/, "请输入正确的手机号") == false) {

            } else if (this.$vali(this.Password, /^[a-zA-Z0-9_]{6}$/, "请输入正确的密码") == false) {

            } else {
                this.$http({
                    method: 'post',
                    url: localPath + '/user/mobilePhoneLogin',
                    data: params
                }).then((response) => {
                    MessageBox.alert(response.data.message);
                    if (response.data.success) {
                        this.$router.push({ path: '/host' });

                        window.localStorage.phone = this.username;
                        window.localStorage.Password = this.Password;
                    }
                    console.log(response);
                }).catch((error) => {
                    console.log(error);
                })
            }
        },
        bear() {
            if (window.localStorage.phone == undefined || window.localStorage.phone == "") {
            }else{
                this.username = window.localStorage.phone;
                this.Password = window.localStorage.Password;
                this.login();
            }
        }

    },
    mounted() {
        this.bear();
    },
}

</script>
<style>

</style>